﻿// This file is part of Code4Public (http://code4public.codeplex.com)
// Copyright 2011 Sina Iravanian - <sina@sinairv.com>
//
// This source file(s) may be redistributed, altered and customized
// by any means PROVIDING the authors name and all copyright
// notices remain intact.
// THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED. USE IT AT YOUR OWN RISK. THE AUTHOR ACCEPTS NO
// LIABILITY FOR ANY DATA DAMAGE/LOSS THAT THIS PRODUCT MAY CAUSE.
// ------------------------------------------------------------------


using System;
using System.Text;
using YAXLib;

namespace Code4Public.Languages
{
    public class StringInfo
    {
        public StringInfo()
        {
        }

        public StringInfo(string startsWith, string endsWith, string escapes)
        {
            StartsWith = startsWith;
            EndsWith = endsWith;
            Escapes = escapes.Split(',');
        }


        [YAXAttributeFor(".#startswith")]
        public string StartsWith { get; private set; }

        [YAXAttributeFor(".#endswith")]
        public string EndsWith { get; private set; }

        [YAXAttributeFor(".#escape")]
        [YAXCollection(YAXCollectionSerializationTypes.Serially, SeparateBy=",")]
        public string[] Escapes { get; private set; }

        public string GetEscapesString()
        {
            var sb = new StringBuilder();
            bool isFirst = true;

            foreach (string esc in Escapes)
            {
                if (isFirst)
                {
                    sb.Append(esc);
                    isFirst = false;
                }
                else
                {
                    sb.Append("," + esc);
                }
            }

            return sb.ToString();
        }

        public override string ToString()
        {
            return String.Format("StringInfo - StartsWith: [{0}] - EndsWith: [{1}] - Escape: [{2}]", 
                StartsWith, EndsWith, GetEscapesString());
        }

    }
}
